package com.jeesite.modules.common.response;

import java.io.Serializable;

public class ResponseObj<T>  implements Serializable {
	public static final  int  SUCCESS_CODE=200;

	public static final String SUCCESS_MSG="SUCCESS";

	private int  code;

	private T data;

	private String message;

	private String token;



	public String getToken() {
		return token;
	}

	public ResponseObj setToken(String token) {
		this.token = token;
		return  this;
	}

	public int getCode() {
		return code;
	}

	public ResponseObj setCode(int code) {
		this.code = code;
		return  this;
	}


	public T getData() {
		return data;
	}

	public ResponseObj setData(T data) {
		this.data = data;
		return  this;
	}

	public String getMessage() {
		return message;
	}

	public ResponseObj setMessage(String message) {
		this.message = message;
		return  this;
	}

	public static <T> ResponseObj<T> createResponse(int code, String msg, String token){
		return   new ResponseObj<T>() .setCode(code).setMessage(msg).setToken(token);
	}

	public static <T> ResponseObj<T> createResponse(int code, String msg){
		return   new ResponseObj<T>() .setCode(code).setMessage(msg);
	}

	public static <T> ResponseObj<T> createSuccessResponse(T obj, String token){
		return  createResponse(SUCCESS_CODE,SUCCESS_MSG,token).setData(obj);
	}

	public static <T> ResponseObj<T> createSuccessResponse(T obj){
		return  createResponse(SUCCESS_CODE,SUCCESS_MSG).setData(obj);
	}

	public static <T> ResponseObj<T> createSuccessResponse(String token){
		return  createResponse(SUCCESS_CODE,SUCCESS_MSG,token);
	}

	public static <T> ResponseObj<T> createSuccessResponse(){
		return  createResponse(SUCCESS_CODE,SUCCESS_MSG);
	}

	public static ResponseObj createErrResponse(int code, String message, String token){
		return createResponse(code,message,token);
	}
	public static ResponseObj createErrResponse(int code, String message){
		return createResponse(code,message);
	}


	@Override
	public String toString() {
		return "{code=" + code +
				", data=" + data +
				", message='" + message + '\''+"}";
	}
}
